<template>
    <div class="main">
        <!-- 导航栏 -->
        <div>
            <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item>反馈信息管理></el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <!-- 表格 -->
        <div>
            <el-card class="box-card">
                <div>
                    <div style="float:left">
                        <!-- <el-button type="success">发布文章</el-button> -->
                        <el-select v-model="value" style="width:135px" placeholder="请选择">
                            <el-option
                            v-for="item in options"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                            </el-option>
                        </el-select>
                        <el-input v-model="value2" style="width:250px"></el-input>
                        <el-button @click="mohuchaxun()" type="success">查询</el-button>
                        <el-button type="success" @click="chongzhi()">重置</el-button>
                    </div>
                <el-table
                :data="tableData"
                height="500px"
                stripe
                style="width: 100%">
                <el-table-column
                type="index"
                >
                </el-table-column>
                <el-table-column
                prop="studentId"
                show-overflow-tooltip
                label="学号">
                </el-table-column>
                <el-table-column
                prop="type"
                show-overflow-tooltip
                label="类型">
                </el-table-column>
                <el-table-column
                prop="content"
                show-overflow-tooltip
                label="反馈内容">
                </el-table-column>
                <el-table-column
                prop="telephone"
                label="联系方式">
                </el-table-column>
                <el-table-column
                prop="feedbackTime"
                show-overflow-tooltip
                label="反馈时间">
                </el-table-column>
                <el-table-column
                prop="feedbackResult"
                label="反馈结果">
                <template slot-scope="scope">
                    <el-tag type="danger" v-if="scope.row.feedbackResult==0">未处理</el-tag>
                    <el-tag v-else>已处理</el-tag>
                </template>
                </el-table-column>
                <el-table-column
                prop="address"
                label="操作">
                <template slot-scope="scope">
                    <el-button @click="editData(scope.row)" type="text" size="small">处理</el-button>
                    <el-button @click="deleteData(scope.row)" type="text" size="small">删除</el-button>
                </template>
                </el-table-column>
            </el-table>
            </div>
            <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="count"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
            </el-pagination>
            </el-card>
            <el-dialog
            title="编辑"
            :visible.sync="centerDialogVisible"
            width="45%"
            height="450px"
            center>
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="学号">
                    <el-input v-model="form.studentId" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="类型">
                    <el-input v-model="form.type" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="反馈内容">
                    <el-input v-model="form.content" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="联系方式">
                    <el-input v-model="form.telephone" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="反馈时间">
                    <el-input v-model="form.feedbackTime" :disabled="true"></el-input>
                </el-form-item>
                <el-form-item label="反馈结果">
                    <el-select v-model="form.feedbackResult" placeholder="请选择">
                    <el-option label="已处理" value="1"></el-option>
                    <el-option label="未处理" value="0"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="centerDialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="commitData()">提交</el-button>
            </span>
            </el-dialog>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{
            tableData:[],
            total:10,
            page:1,
            count:10,
            centerDialogVisible:false,
            form:{},
            options:[
                {value:'0',label:'学号'},
                {value:'1',label:'未处理'},
                {value:'2',label:'已处理'},
            ],
            value:'',
            value2:'',
        }
    },
    methods:{
         getData(){
            var _this=this
            var url='http://taruinfo.work:8088/feedback/selectByPageCount?page='+this.page+'&pageCount='+this.count
            _this.$axios.get(url).then(function(res){
                // console.log(res.data)
                if(res.data.code==200){
                  _this.total=res.data.data.feedback.total
                  _this.tableData=res.data.data.feedback.records
                }else{
                    console.log('获取反馈信息失败')
                }
            })
        },
        handleSizeChange(val){
            this.count=val
            this.getData()
        },
        handleCurrentChange(val){
            this.page=val
            this.getData()
        },
        editData(row) {
            console.log(row)
            this.form=row
            this.centerDialogVisible=true
        },
        commitData(){
            var _this=this
            var url='http://taruinfo.work:8088/feedback/updateByID'
            _this.$axios.put(url,_this.form).then(function(res){
                if(res.data.code==200){
                    _this.$message({
                      message: '更新成功',
                      type: 'success'
                    })
                    _this.centerDialogVisible=false
                    _this.getData()
                }else{
                   _this.$message({
                      message: '更新失败',
                      type: 'error'
                    })
                   _this.centerDialogVisible=false 
                }
            })
        },

        deleteData(row){
            var _this=this
            var url='http://taruinfo.work:8088/feedback/deleteByID?id='+row.id
            _this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
                _this.$axios.delete(url).then(function(res){
                if(res.data.code==200){
                    _this.$message({
                        type: 'success',
                        message: '删除成功!'
                    })
                    _this.getData()
                }else{
                    _this.$message({
                        type: 'error',
                        message: '删除失败!'
                    })
                }
            })  
            }).catch(() => {
                _this.$message({
                    type: 'info',
                    message: '已取消删除'
                })         
            })
        console.log(row)
        },
        chongzhi(){
            this.getData()
        },
        mohuchaxun(){
            var _this=this
            var url1='http://taruinfo.work:8088/feedback/likeFeedbackByLists?current=1&size=10&studentId='+_this.value2
            var url2='http://taruinfo.work:8088/feedback/likeFeedbackByLists?current=1&feedbackResult=0&size=10'
            var url3='http://taruinfo.work:8088/feedback/likeFeedbackByLists?current=1&feedbackResult=1&size=10'
            if(_this.value=='0'){
                if(_this.value2!=''){
                    _this.$axios.get(url1).then(function(res){
                console.log(res.data)
                if(res.data.code =='200'){
                _this.total=res.data.data.total
                _this.tableData=res.data.data.records
                _this.value=''
                _this.value2=''
                }else{
                    console.log('获取信息失败')
                }
                })
                }else{
                    _this.$message({
                        message: '条件不能为空',
                        type: 'warning'
                    })
                }
                
            }else if(_this.value=='1'){
                _this.$axios.get(url2).then(function(res){
                console.log(res.data)
                if(res.data.code =='200'){
                _this.total=res.data.data.total
                _this.tableData=res.data.data.records
                _this.value=''
                _this.value2=''
                }else{
                    console.log('获取信息失败')
                }
            })
            }else if(_this.value=='2'){
                _this.$axios.get(url3).then(function(res){
                console.log(res.data)
                if(res.data.code =='200'){
                _this.total=res.data.data.total
                _this.tableData=res.data.data.records
                _this.value=''
                _this.value2=''
                }else{
                    console.log('获取信息失败')
                }
            })
            }else{

            }
        }
    },
    mounted(){

    },
    created(){
        this.getData()
    }
}
</script>

<style scoped>
.box-card{
    width: 1270px;
    height:615px;
    margin-top: 10px;
}
</style>